<?php include "../public/header.php"?>
<?php include "../public/header_public.php"?>
<body class="laytp-container">
    <div style="height: 45px"></div>
    <div id="opt_nav">
    </div>
    <div id="dialog">
        <div class="page-title" id="page-title">
            <div class="page-title-con">
                <span class="title">选择用证信息</span>
                <div class="move_title"></div>
                <div class="page-title-opt-list">
                    <button class="layui-btn layui-btn-sm btn-dark marginr5" type="button" id="submit">确定</button>
                    <span id="page-close" class="page-close" onclick="layer_close()">×</span>
                </div>
            </div>
        </div>
    </div>

    <div class="layui-card" id="search-form">
        <div class="layui-card-body">
            <form class="layui-form" id="TableSearchFormId" lay-filter="TableSearchForm" onkeydown="keyTableSearch('TableSearchForm', 'datalist')">
                <div class="layui-form-item">
                    <div class="layui-row">
                        <div class="layui-col-md3">
                            <label class="layui-form-label">所属单位</label>
                            <div class="layui-input-block">
                                <div id="chanid" class="xmselect_div">
                                    <div class="xmselect_title">请选择</div>
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-md3">
                            <label class="layui-form-label">申请人</label>
                            <div class="layui-input-block">
                                <input type="text" name="created_user" placeholder="请输入" class="layui-input" autocomplete="off">
                            </div>
                        </div>
                        <div class="layui-col-md3">
                            <label class="layui-form-label">申请日期</label>
                            <div class="layui-input-block">
                                <input type="text" name="created_at" placeholder="请输入" class="layui-input bdate_ymd" autocomplete="off">
                            </div>
                        </div>
                        <div class="layui-col-md3 search_hide none">
                            <label class="layui-form-label">用证项目</label>
                            <div class="layui-input-block">
                                <input type="text" name="enginid" placeholder="请输入" class="layui-input" autocomplete="off">
                            </div>
                        </div>
                        <div class="layui-col-md3 search_hide none">
                            <label class="layui-form-label">报建日期</label>
                            <div class="layui-input-block">
                                <input type="text" name="dt" placeholder="请输入" class="layui-input bdate_ymd" autocomplete="off">
                            </div>
                        </div>
                        <div class="layui-col-md3">
                            <div class="layui-form-item search-div">
                                <input type="hidden" id="type" name="type" value="2">
                                <div class="layui-form-item layui-inline">
                                    <button class="laytp-btn laytp-btn-md laytp-btn-primary" id="TableSearchButton" type="button"><i class="layui-icon layui-icon-search"></i>查询</button>
                                    <button class="layui-btn layui-btn-primary" onclick="listTableReset()" id="TableSearchReset" type="reset" ><i class="layui-icon layui-icon-refresh"></i>重置</button>
                                    <div id="search_open" onclick="toggle_search()">
                                        <i class="layui-icon layui-icon-down"></i>展开
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>

    <div class="layui-card" id="table-card">
        <div class="layui-card-body">
            <div class="layui-row">
                <div class="layui-col-md12" id="table_list">
                    <div class="layui-card-body">
                        <table id="datalist" lay-filter="datalist"></table>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script type="text/javascript">
        // 重选设置默认选中
        var oldData = getQueryVariable('old_data');
        var oldDataIdArr = [];
        if(oldData){
            oldDataIdArr = oldData.split(',');
        }
        // 单选多选分类 默认单选 choose_type传值为多选
        var choose_type = getQueryVariable('choose_type');
        if(choose_type === undefined || choose_type === false){
            choose_type = 'radio';
        }else{
            choose_type = 'checkbox';
        }
        // 是否赋值在同一个节点上 默认赋值两个节点
        var input = getQueryVariable('input');
        if(input === undefined || input === false){
            input = 'multi';
        }else{
            input = 'single';
        }

        // 页面绑定节点元素
        var parent_dom = getQueryVariable('dom');
        // 页面分类
        var parent_page = getQueryVariable('page');

        // 传递参数
        var parent_status = getQueryVariable('status');
        if(parent_status === undefined || parent_status === false){
            parent_status = '';
        }
        var parent_goes = getQueryVariable('goes');
        if(parent_goes === undefined || parent_goes === false){
            parent_goes = '';
        }


        var issuoArr = [];
        var currButAuth, currTabData, treeObj, treeData = [], treeStatus = 2, sea_store_addr='', sea_chanid=''
            , queryStatus = 0, sea_person_nature='';
        layui.use(['table','form','element','facade'],function() {
            var table = layui.table;
            var facade = layui.facade;

            $('#TableSearchReset').click(function () {
                sea_store_addr='';sea_chanid='';sea_person_nature='';
                $('.xmselect_div>xm-select').find('.xm-label-block').css('display','none');
                $('.xmselect_div').append('<div class="xmselect_title">请选择</div>');
                searchTableFunc(form, table)
            });

            table.render({
                elem: '#datalist'
                ,toolbar: false
                ,defaultToolbar: false
                ,method:'post'
                ,url: facade.url(ask_opt_get_cert_use)
                ,page: true
                ,height: 'full-140'
                ,where: {status: parent_status, goes: parent_goes}
                ,request: {pageName: 'page',limitName: 'pagesize'}
                ,parseData: function(res){

                    xmselect_dan('chanid', res.data.chanid, sea_chanid, function (res) {
                        sea_chanid = res.arr && res.arr.length > 0 ?  res.arr[0].value : '';
                        searchTableFunc(form, table);
                    });

                    render_from();
                    return {
                        "code": res.code,
                        "msg": res.message,
                        "count": res.data.data.total,
                        "data": res.data.data.data
                    };
                }
                ,response: {statusCode: 2000}
                ,cols: [[
                    {type:choose_type,fixed:'left'}
                    ,{type:'numbers',title:'序号',fixed:'left'}
                    ,{field: 'flowuser', title: '申请人',width: 100}
                    ,{field: 'created_at', title: '申请时间',width: 100}
                    ,{field: 'type_name', title: '用证类型'}
                    ,{field: 'engin_name', title: '项目名称'}
                    ,{field: 'dt', title: '报建日期'}
                    ,{field: 'num', title: '用证数量'}
                    ,{field: 'explain', title: '用证说明'}
                ]]
                // 重选设置默认选中
                ,done : function(res, curr, count){
                    soulTable.render(this);
                }
            });


            $('#submit').on('click', function () {
                var checkStatus = layui.table.checkStatus('datalist');
                var data = checkStatus.data;
                if(data.length === 0){
                    facade.error('请选择数据'); return false;
                }

                if(parent_page === 'cert_borrow'){
                    var str = '';
                    var length = $('#short_table_tbody_ren tr', parent.document).length;
                    for(var i=0;i<data.length;i++){
                        str += '<tr>';
                        str += '<td class="width35">'+(length + i + 1)+'</td>';
                        str += '<td>'+data[i].name+'<input type="hidden" class="certid" value="'+data[i].id+'"></td>';
                        str += '<td>'+data[i].number+'</td>';
                        str += '<td>'+data[i].major_name+'</td>';
                        str += '<td>'+data[i].expiry_dt+'</td>';
                        str += '<td>'+data[i].electron_dt+'</td>';
                        str += '<td>'+data[i].goes_name+'</td>';
                        str += '<td>'+data[i].use_name+'</td>';
                        str += '<td>'+data[i].person_name+'</td>';
                        str += '<td>'+data[i].person_state+'</td>';
                        str += '<td>'+data[i].com_name+'</td>';
                        str += '</tr>';
                    }
                    $('#short_table_tbody_ren', parent.document).append(str);
                    parent.update_refresh_row_func();
                }

                layer_close();
            });

            // 清空
            $('#empty').on('click', function () {
                $("#"+parent_dom+'_name' , parent.document).val('');
                $("#"+parent_dom , parent.document).val('');
                layer_close();
            });
        });
    </script>
</body>
</html>
